package main

import "fmt"

type Book struct {
	title   string
	author  string
	subject string
	book_id int
}

// 结构体的方法
func (b Book) sout() {
	fmt.Printf("title: %s, author: %s, subject: %s, book_id %d\n", b.title, b.author, b.subject, b.book_id)
}

// 结构体作为入参
func sout(book Book) {
	fmt.Println(book.book_id)
	fmt.Println(book.title)
	fmt.Println(book.author)
	fmt.Println(book.subject)
}

func pointPrint(book *Book) {
	fmt.Println(book.book_id)
	fmt.Println(book.title)
	fmt.Println(book.author)
	fmt.Println(book.subject)
}

// 结构体
func structG() {
	fmt.Println()
	fmt.Println("=========structG========")
	fmt.Println()
	// 默认顺序
	Book{"金瓶梅子", "jathonkatu", "文学", 1}.sout()
	// 指定字段名
	Book{title: "红楼梦遗", author: "jathonkatu", subject: "文学", book_id: 2}.sout()
	// 忽略的字段就是默认值
	Book{title: "水浒传纸条", author: "jathonkatu"}.sout()

	var book1 Book
	book1.book_id = 3
	book1.title = "梦回大唐"
	book1.author = "author"
	book1.subject = "文学"
	fmt.Println(book1.book_id)
	fmt.Println(book1.title)
	fmt.Println(book1.author)
	fmt.Println(book1.subject)

	var book2 = Book{"金瓶梅子", "jathonkatu", "文学", 4}
	sout(book2)

	fmt.Println("")
	fmt.Println("ponit print")
	fmt.Println("")
	pointPrint(&book1)
	pointPrint(&book2)
}
